package com.code.generator;


import com.code.config.DataSourceInfo;
import com.code.config.DataSourceSql;
import com.code.entity.metadata.Column;

import java.sql.ResultSet;
import java.sql.SQLException;

public class GenerateParams {

    public static void setColumnInfo(ResultSet columnResultSet, Column column) throws SQLException {
        if (DataSourceSql.dm.getType().equals(DataSourceInfo.DRIVER_CLASS.getValue())) {
            String ordinalPosition = columnResultSet.getString("ordinal_position");
            column.setPrimary("1".equals(ordinalPosition));
            String primaryKey = columnResultSet.getString("extra");
            column.setPrimaryKey(primaryKey);
        }

        if (DataSourceSql.mysql.getType().equals(DataSourceInfo.DRIVER_CLASS.getValue())) {
            column.setPrimary("PRI".equalsIgnoreCase(columnResultSet.getString("column_key")));
            column.setAutoIncrement("auto_increment".equalsIgnoreCase(columnResultSet.getString("extra")));
            column.setPrecision(columnResultSet.getInt("numeric_precision"));
            column.setScale(columnResultSet.getInt("numeric_scale"));

        }
    }

}
